home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / SciAn / src / ScianVisNumbers.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  15KB  |  481 lines

  1. /*ScianVisSticks.c
  2.   November 9, 1992
  3.   Eric Pepke
  4.   Numbers visualization object in SciAn*/
  5.  
  6. #include "Scian.h"
  7. #include "ScianTypes.h"
  8. #include "ScianArrays.h"
  9. #include "ScianWindows.h"
  10. #include "ScianTextBoxes.h"
  11. #include "ScianButtons.h"
  12. #include "ScianTitleBoxes.h"
  13. #include "ScianObjWindows.h"
  14. #include "ScianIcons.h"
  15. #include "ScianColors.h"
  16. #include "ScianControls.h"
  17. #include "ScianLists.h"
  18. #include "ScianSliders.h"
  19. #include "ScianIDs.h"
  20. #include "ScianDatasets.h"
  21. #include "ScianPictures.h"
  22. #include "ScianDialogs.h"
  23. #include "ScianErrors.h"
  24. #include "ScianComplexControls.h"
  25. #include "ScianMethods.h"
  26. #include "ScianStyle.h"
  27. #include "ScianVisObjects.h"
  28. #include "ScianVisNumbers.h"
  29. #include "ScianDraw.h"
  30. #include "ScianTemplates.h"
  31. #include "ScianTemplateHelper.h"
  32. #include "ScianTimers.h"
  33. #include "ScianSpaces.h"
  34. #include "ScianDrawings.h"
  35.  
  36. ObjPtr visNumbers;    /*Class for numbers object*/
  37.  
  38. static ObjPtr AddNumbersControls(object, panelContents)
  39. ObjPtr object, panelContents;
  40. /*Adds controls to a numbers object*/
  41. {
  42.     ObjPtr titleBox, textBox, checkBox, slider, colorWheel;
  43.     ObjPtr var;
  44.     ObjPtr corral, icon, name;
  45.     ObjPtr numbersField;
  46.     ObjPtr defaultIcon;
  47.  
  48.     /*Add in the corral*/
  49.     corral = NewIconCorral(NULLOBJ,
  50.                MAJORBORDER, MAJORBORDER + ONECORRALWIDTH,
  51.                CWINHEIGHT - MAJORBORDER - ONECORRALHEIGHT,
  52.                CWINHEIGHT - MAJORBORDER, 0);
  53.     SetVar(corral, SINGLECORRAL, ObjTrue);
  54.     SetVar(corral, TOPDOWN, ObjTrue);
  55.     SetVar(corral, NAME, NewString("Number Field"));
  56.     SetVar(corral, HELPSTRING,
  57.     NewString("This corral shows the dataset that is being used to make \
  58. the numeric display.  The value shown and the position display, if any, is \
  59. calculated from this field.  The color of the position display is calculated \
  60. using the Color Field, available in the Color control set."));
  61.     PrefixList(panelContents, corral);
  62.     SetVar(corral, PARENT, panelContents);
  63.     SetVar(corral, REPOBJ, object);
  64.     SetMethod(corral, DROPINCONTENTS, DropInMainDatasetCorral);
  65.  
  66.  
  67.     /*Create the numbers source text box*/
  68.     textBox = NewTextBox(MAJORBORDER, MAJORBORDER + ONECORRALWIDTH, 
  69.              CWINHEIGHT - MAJORBORDER - ONECORRALHEIGHT - TEXTBOXSEP - TEXTBOXHEIGHT,
  70.              CWINHEIGHT - MAJORBORDER - ONECORRALHEIGHT - TEXTBOXSEP,
  71.              0, "Number Field Text", "Number Field");
  72.     PrefixList(panelContents, textBox);
  73.     SetVar(textBox, PARENT, panelContents);
  74.     SetTextAlign(textBox, CENTERALIGN);
  75.  
  76.     /*Put in an icon that represents the field*/
  77.     numbersField = GetVar(object, MAINDATASET);
  78.     name = GetVar(numbersField, NAME);
  79.     defaultIcon = GetVar(numbersField, DEFAULTICON);
  80.     if (defaultIcon)
  81.     {
  82.     icon = NewObject(defaultIcon, 0);
  83.     SetVar(icon, NAME, name);
  84.     }
  85.     else
  86.     {
  87.     icon = NewIcon(0, 0, ICONQUESTION, GetString(name));
  88.     }
  89.     SetVar(icon, ICONLOC, NULLOBJ);
  90.     SetVar(icon, REPOBJ, numbersField);
  91.     DropIconInCorral(corral, icon);
  92.  
  93.     /*Add in the group of controls for text color*/
  94.     titleBox = TemplateTitleBox(VisNumbersTemplate, "Text");
  95.     SetVar(titleBox, PARENT, panelContents);
  96.     PrefixList(panelContents, titleBox);
  97.  
  98.     /*Make the color wheel*/
  99.     colorWheel = TemplateColorWheel(VisNumbersTemplate, "Text Color");
  100.     SetVar(colorWheel, PARENT, panelContents);
  101.     PrefixList(panelContents, colorWheel);
  102.     AssocColorControlWithVar(colorWheel, object, COLOR);
  103.     SetVar(colorWheel, HELPSTRING, NewString("This color wheel controls the \
  104. hue and saturation of the color used to draw the text in the numeric display.  \
  105. The final color is a combination of this hue and saturation and the value, or brightness, \
  106. given by the Value slider."));
  107.     
  108.     /*Make the text box below*/
  109.     textBox = TemplateTextBox(VisNumbersTemplate, "Text Color Label", PLAIN, "Color");
  110.     SetVar(textBox, PARENT, panelContents);
  111.     PrefixList(panelContents, textBox);
  112.     SetTextAlign(textBox, CENTERALIGN);
  113.  
  114.     /*Make the brightness slider*/
  115.     slider = TemplateSlider(VisNumbersTemplate, "Text Color Value", PLAIN);
  116.     SetVar(slider, PARENT, panelContents);
  117.     PrefixList(panelContents, slider);
  118.     SetSliderRange(slider, 1.0, 0.0, 0.0);
  119.     AssocBrightnessControlWithVar(slider, object, COLOR);
  120.     SetVar(slider, HELPSTRING, NewString("This slider controls the \
  121. value, or brightness, of the color used to draw the text in the numeric display.  \
  122. The final color is a combination of this value and the hue and saturation \
  123. given by the Color color wheel."));
  124.  
  125.     /*Make the text box below*/
  126.     textBox = TemplateTextBox(VisNumbersTemplate, "Text Value Label", PLAIN, "Value");
  127.     SetVar(textBox, PARENT, panelContents);
  128.     PrefixList(panelContents, textBox);
  129.     SetTextAlign(textBox, CENTERALIGN);
  130.  
  131.     /*Make the background controls*/
  132.     titleBox = TemplateTitleBox(VisNumbersTemplate, "Background");
  133.     SetVar(titleBox, PARENT, panelContents);
  134.     PrefixList(panelContents, titleBox);
  135.  
  136.     /*Make the color wheel*/
  137.     colorWheel = TemplateColorWheel(VisNumbersTemplate, "Background Color");
  138.     SetVar(colorWheel, PARENT, panelContents);
  139.     PrefixList(panelContents, colorWheel);
  140.     AssocColorControlWithVar(colorWheel, object, BACKGROUND);
  141.     SetVar(colorWheel, HELPSTRING, NewString("This color wheel controls the \
  142. hue and saturation of the color used to draw the background of the numeric display.  \
  143. The final color is a combination of this hue and saturation and the value, or brightness, \
  144. given by the Value slider."));
  145.     
  146.     /*Make the text box below*/
  147.     textBox = TemplateTextBox(VisNumbersTemplate, "Background Color Label", PLAIN, "Color");
  148.     SetVar(textBox, PARENT, panelContents);
  149.     PrefixList(panelContents, textBox);
  150.     SetTextAlign(textBox, CENTERALIGN);
  151.  
  152.     /*Make the brightness slider*/
  153.     slider = TemplateSlider(VisNumbersTemplate, "Background Value", PLAIN);
  154.     SetVar(slider, PARENT, panelContents);
  155.     PrefixList(panelContents, slider);
  156.     SetSliderRange(slider, 1.0, 0.0, 0.0);
  157.     AssocBrightnessControlWithVar(slider, object, BACKGROUND);
  158.     SetVar(slider, HELPSTRING, NewString("This slider controls the \
  159. value, or brightness, of the color used to draw the background of the numeric display.  \
  160. The final color is a combination of this value and the hue and saturation \
  161. given by the Color color wheel."));
  162.  
  163.     /*Make the text box below*/
  164.     textBox = TemplateTextBox(VisNumbersTemplate, "Background Value Label", PLAIN, "Value");
  165.     SetVar(textBox, PARENT, panelContents);
  166.     PrefixList(panelContents, textBox);
  167.     SetTextAlign(textBox, CENTERALIGN);
  168.  
  169.     /*Make the check box*/
  170.     checkBox = TemplateCheckBox(VisNumbersTemplate, "No Background", false);
  171.     SetVar(checkBox, PARENT, panelContents);
  172.     PrefixList(panelContents, checkBox);
  173.     AssocInhibitControlWithVar(checkBox, object, BACKGROUND, NewInt(UIBLACK));
  174.     SetVar(checkBox, HELPSTRING, NewString("This checkbox controls whether \
  175. a background is shown.  If it is selected, no background is shown, and the \
  176. objects behind can be seen."));
  177.  
  178.     /*Create the format text box*/
  179.     textBox = TemplateTextBox(VisNumbersTemplate, "Format:", PLAIN, "Format:");
  180.     PrefixList(panelContents, textBox);
  181.     SetVar(textBox, PARENT, panelContents);
  182.  
  183.     /*Create the enter format text box*/
  184.     MakeVar(object, FORMAT);
  185.     var = GetVar(object, FORMAT);
  186.     textBox = TemplateTextBox(VisNumbersTemplate, "Format Text",
  187.     EDITABLE + WITH_PIT + ONE_LINE, 
  188.     var ? GetString(var): "");
  189.     PrefixList(panelContents, textBox);
  190.     SetVar(textBox, PARENT, panelContents);
  191.     AssocDirectControlWithVar(textBox, object , FORMAT);
  192.     SetVar(textBox, HELPSTRING, NewString(
  193.     "This text box contains the format used to print the numeric value \
  194. in the field.  It works very much like the UNIX function printf, except that \
  195. all conversions in the field refer to the same number."));
  196.     
  197.  
  198.     return ObjTrue;
  199. }
  200.  
  201. static ObjPtr NumbersInit(numbers)
  202. ObjPtr numbers;
  203. /*Initializes a numbers object*/
  204. {
  205.     ObjPtr repObj, var;
  206.  
  207.     /*Set the format to the dataset name*/
  208.     repObj = GetVar(numbers, MAINDATASET);
  209.     if (repObj)
  210.     {
  211.     ObjPtr ds;
  212.     ds = repObj;
  213.     while (repObj = GetVar(ds, MAINDATASET))
  214.     {
  215.         ds = repObj;
  216.     }
  217.     MakeVar(ds, NAME);
  218.     var = GetVar(ds, NAME);
  219.     if (var)
  220.     {
  221.         sprintf(tempStr, "%s=%%g", GetString(var));
  222.         SetVar(numbers, FORMAT, NewString(tempStr));
  223.     }
  224.  
  225.     if (0 == (GetDatasetInfo(repObj) &  DS_HASFORM))
  226.     {
  227.         SetVar(numbers, ABORTCONTROLS, ObjTrue);
  228.     }
  229.     }
  230.  
  231.     return ObjTrue;
  232. }
  233.  
  234. static ObjPtr SetNumbersMainDataset(visObj, dataSet)
  235. ObjPtr visObj, dataSet;
  236. /*Sets the main data set of visObj to dataSet*/
  237. {
  238.     SetVar(visObj, MAINDATASET, dataSet);
  239.     return ObjTrue;
  240. }
  241.  
  242. static ObjPtr MakeReadoutValue(readout)
  243. ObjPtr readout;
  244. /*Makes the VALUE of a readout*/
  245. {
  246.     ObjPtr var, format, repObj;
  247.     real value;
  248.     char s[400];
  249.  
  250.     repObj = GetObjectVar("MakeReadoutValue", readout, REPOBJ);
  251.     if (!repObj)
  252.     {
  253.     return ObjFalse;
  254.     }
  255.  
  256.     MakeVar(repObj, VALUE);
  257.     var = GetVar(repObj, VALUE);
  258.     if (!var)
  259.     {
  260.     value = 0.0;
  261.     }
  262.     else
  263.     {
  264.     value = GetReal(var);
  265.     }
  266.  
  267.     MakeVar(readout, FORMAT);
  268.     format = GetVar(readout, FORMAT);
  269.     if (format)
  270.     {
  271.     PrintClock(s, GetString(format), value);
  272.     }
  273.     else
  274.     {
  275.         sprintf(s, "%#.2f", time);
  276.     }
  277.  
  278.     SetVar(readout, VALUE, NewString(s));
  279.  
  280.     return ObjTrue;
  281. }
  282.  
  283. static ObjPtr MakeNumbersReadoutAppearance(readout)
  284. ObjPtr readout;
  285. /*Dummy make for numbers readout appearance*/
  286. {
  287.     SetVar(readout, APPEARANCE, ObjTrue);
  288.     ImInvalid(readout);
  289.     return ObjTrue;
  290. }
  291.  
  292. static ObjPtr MakeNumbersReadoutColor(readout)
  293. ObjPtr readout;
  294. /*Makes the COLOR of a numbers readout*/
  295. {
  296.     ObjPtr repObj;
  297.     repObj = GetVar(readout, REPOBJ);
  298.     if (repObj)
  299.     {
  300.     SetVar(readout, COLOR, GetVar(repObj, COLOR));
  301.     }
  302.     return ObjTrue;
  303. }
  304.  
  305. static ObjPtr MakeNumbersReadoutBackground(readout)
  306. ObjPtr readout;
  307. /*Makes the BACKGROUND of a numbers readout*/
  308. {
  309.     ObjPtr repObj;
  310.     repObj = GetVar(readout, REPOBJ);
  311.     if (repObj)
  312.     {
  313.     SetVar(readout, BACKGROUND, GetVar(repObj, BACKGROUND));
  314.     }
  315.     return ObjTrue;
  316. }
  317.  
  318. static ObjPtr MakeNumbersReadoutFormat(readout)
  319. ObjPtr readout;
  320. /*Makes the FORMAT of a numbers readout*/
  321. {
  322.     ObjPtr repObj;
  323.     repObj = GetVar(readout, REPOBJ);
  324.     if (repObj)
  325.     {
  326.     SetVar(readout, FORMAT, GetVar(repObj, FORMAT));
  327.     }
  328.     return ObjTrue;
  329. }
  330.  
  331. #ifdef PROTO
  332. static ObjPtr NewNumericReadout(int left, int right, int bottom, int top, char *name, ObjPtr space)
  333. #else
  334. static ObjPtr NewNumericReadout(left, right, bottom, top, name, space)
  335. int left, right, bottom, top;
  336. char *name;
  337. ObjPtr space;
  338. /*Returns a new numeric readout*/
  339. #endif
  340. {
  341.     ObjPtr readout;
  342.     readout = NewTextBox(left, right, bottom, top, ADJUSTABLE, name, "");
  343.     DeclareDependency(readout, VALUE, FORMAT);
  344.     SetVar(readout, SPACE, space);
  345.     SetVar(readout, REPOBJONLY, ObjTrue);
  346.  
  347.     DeclareIndirectDependency(readout, VALUE, SPACE, TIME);
  348.     DeclareIndirectDependency(readout, VALUE, REPOBJ, VALUE);
  349.  
  350.     SetMethod(readout, VALUE, MakeReadoutValue);
  351.  
  352.     SetVar(readout, HELPSTRING, NewString("This numeric readout displays \
  353. a single scalar value from a dataset.  The display format is controlled by the Format \
  354. text box in the readout's control panel.\n"));
  355.     DeclareIndirectDependency(readout, APPEARANCE, REPOBJ, SELECTED);
  356.     DeclareDependency(readout, APPEARANCE, COLOR);
  357.     DeclareDependency(readout, APPEARANCE, BACKGROUND);
  358.     DeclareIndirectDependency(readout, APPEARANCE, REPOBJ, SELECTED);
  359.     SetMethod(readout, APPEARANCE, MakeNumbersReadoutAppearance);
  360.  
  361.     DeclareIndirectDependency(readout, COLOR, REPOBJ, COLOR);
  362.     SetMethod(readout, COLOR, MakeNumbersReadoutColor);
  363.  
  364.     DeclareIndirectDependency(readout, FORMAT, REPOBJ, FORMAT);
  365.     SetMethod(readout, FORMAT, MakeNumbersReadoutFormat);
  366.  
  367.     DeclareIndirectDependency(readout, BACKGROUND, REPOBJ, BACKGROUND);
  368.     SetMethod(readout, BACKGROUND, MakeNumbersReadoutBackground);
  369.  
  370.     return readout;
  371. }
  372.  
  373. int nNumericReadouts = 0;
  374.  
  375. static ObjPtr DroppedNumbersInSpace(numbers, space)
  376. ObjPtr numbers, space;
  377. /*Called when a numbers object is dropped in a space*/
  378. {
  379.     ObjPtr frontPanel;
  380.     ObjPtr screenObject;
  381.     char name[256];
  382.     ObjPtr var;
  383.  
  384.     frontPanel = GetVar(space, FRONTPANEL);
  385.     if (!frontPanel)
  386.     {
  387.     return ObjFalse;
  388.     }
  389.  
  390.     sprintf(name, "Numeric readout text %d", ++nNumericReadouts);
  391.  
  392.     screenObject = NewNumericReadout(20, 380, 20, 80, name, space);
  393.     SetMethod(screenObject, PUSHTOBOTTOM, PushDrawingToBottom);
  394.     SetMethod(screenObject, BRINGTOTOP, BringDrawingToTop);
  395.     SetMethod(screenObject, MOVETOBACKPANEL, MoveDrawingToBackPanel);
  396.     SetMethod(screenObject, MOVETOFRONTPANEL, MoveDrawingToFrontPanel);
  397.  
  398.     SetVar(screenObject, REPOBJ, numbers);
  399.     SetTextColor(screenObject, NewInt(UIWHITE));
  400.     ImInvalid(screenObject);
  401.     SetTextFont(screenObject, ANNOTFONT);
  402.     SetTextSize(screenObject, ANNOTFONTSIZE);
  403.     SetVar(screenObject, STICKINESS, NewInt(FLOATINGLEFT + FLOATINGRIGHT + FLOATINGTOP + FLOATINGBOTTOM));
  404.     PrefixList(GetVar(frontPanel, CONTENTS), screenObject);
  405.     SetVar(screenObject, PARENT, frontPanel);
  406.     SetVar(numbers, READOUT, screenObject);
  407.  
  408.     return ObjTrue;
  409. }
  410.  
  411. static ObjPtr MakeNumbersValue(readout)
  412. ObjPtr readout;
  413. /*Makes a readout's value*/
  414. {
  415.     ObjPtr value;
  416.     ObjPtr field;
  417.     long dummy;
  418.     real sample;
  419.  
  420.     field = GetVar(readout, MAINDATASET);
  421.     if (!field)
  422.     {
  423.     return ObjFalse;
  424.     }
  425.     SetCurField(FIELD1, field);
  426.     sample = SelectFieldScalar(FIELD1, &dummy);
  427.     SetVar(readout, VALUE, NewReal(sample));
  428.     return ObjTrue;
  429. }
  430.  
  431. static ObjPtr MakeNumbersAppearance(numbers)
  432. ObjPtr numbers;
  433. /*Makes a number's appearance*/
  434. {
  435.     ImInvalid(numbers);
  436.     SetVar(numbers, APPEARANCE, ObjTrue);
  437.     return ObjTrue;
  438. }
  439.  
  440. void InitNumbers()
  441. /*Initializes numbers visualization object*/
  442. {
  443.     ObjPtr icon;
  444.  
  445.     /*Class for a numberic display*/
  446.     visNumbers = NewObject(visClass, 0);
  447.     AddToReferenceList(visNumbers);
  448.     SetVar(visNumbers, NAME, NewString("Number"));
  449.     SetVar(visNumbers, COLOR, NewInt(UIWHITE));
  450.     SetMethod(visNumbers, INITIALIZE, NumbersInit);
  451.     SetVar(visNumbers, DEFAULTICON, icon = NewObject(visIcon, 0));
  452.     SetVar(icon, WHICHICON, NewInt(ICONANNOTATION));
  453.     SetVar(icon, NAME, NewString("Number"));
  454.     SetVar(icon, HELPSTRING,
  455.     NewString("This icon represents a numberic value display object.  \
  456. This object can show the numeric value of any single value in a scalar dataset."));
  457.     DeclareDependency(visNumbers, APPEARANCE, VALUE);
  458.     SetMethod(visNumbers, APPEARANCE, MakeNumbersAppearance);
  459.     SetMethod(visNumbers, SETMAINDATASET, SetNumbersMainDataset);
  460.  
  461.     SetMethod(visNumbers, ADDCONTROLS, AddNumbersControls);
  462.     icon = NewIcon(0, 0, ICONANNOTATION, "Number");
  463.     SetVar(icon, HELPSTRING,
  464.     NewString("Click on this icon to see a panel of controls for the numeric display."));
  465.     SetVar(visNumbers, CONTROLICON, icon);
  466.     SetMethod(visNumbers, DROPPEDINSPACE, DroppedNumbersInSpace);
  467.     DeclareIndirectDependency(visNumbers, VALUE, MAINDATASET, CHANGED);
  468.     SetMethod(visNumbers, VALUE, MakeNumbersValue);
  469.  
  470.     DefineVisMapping(DS_HASFIELD | DS_HASFORM | DS_UNSTRUCTURED, 0, -1, 1, visNumbers);
  471.     DefineVisMapping(DS_HASFIELD | DS_UNSTRUCTURED, 0, -1, 1, visNumbers);
  472.     DefineVisMapping(DS_HASFIELD | DS_HASFORM, 0, -1, 1, visNumbers);
  473.     DefineVisMapping(DS_HASFIELD, 0, -1, 1, visNumbers);
  474. }
  475.  
  476. void KillNumbers()
  477. /*Kills sticks visualization*/
  478. {
  479.     DeleteThing(visNumbers);
  480. }
  481.